package com.kgc.controller;

import com.kgc.pojo.TicketCity;
import com.kgc.pojo.TicketInfo;
import com.kgc.service.GetTicketDetailInfo_wzlService;
import com.kgc.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * 获得票类详情信息的信息
 * @author  王臻利
 */
@RestController
public class GetTicketDetailInfo_wzlController extends BaseController{

    @Autowired
    private GetTicketDetailInfo_wzlService getTicketDetailInfo_wzlService;
    /*获取商品信息*/
    @GetMapping("getTicketDetailInfo_wzl")
    public Object getTicketDetailInfo_wzl() {
        List<TicketInfo> ticketInfos = getTicketDetailInfo_wzlService.getTicketDetailInfo_wzl();
        return new Result(ticketInfos, "获取信息成功");
    }
    /*增加商品信息*/
    @PostMapping("addTicketInfo_wzl")
    public Object addTicketInfo_wzl(TicketInfo ticketInfo, @RequestParam(value = "pic", required = false) MultipartFile pic) throws IOException {
            System.out.println(pic);
            /*找到上传的文件*/
            File file = saveFile(pic);
            //设置文件名
            ticketInfo.setPicpath(file.getName());

        int count=getTicketDetailInfo_wzlService.addTicketInfo_wzl(ticketInfo);
        return new Result(count, "添加订单成功");
    }
    /*删除商品信息*/
    @PostMapping("delTicketInfo_wzl")
    public Object delTicketInfo_wzl(int id){
        int count = getTicketDetailInfo_wzlService.delTicketInfo_wzl(id);
        return new Result(count,"商品信息");
    }
    /*查询城市*/
    @GetMapping("selectcity_wzl")
    public Object selectcity_wzl(){
        List<TicketCity> list = getTicketDetailInfo_wzlService.selectcity_wzl();
        return new Result(list,"查询成功");
    }
}
